﻿using MediatR;
using SY.BasicData.Api.Read.Applications.Slaughter.Command;
using SY.BasicData.Domain.SlaughterInformation;
using SY.BasicData.ErrorCode;
using SY.BasicData.Infrastructures;

namespace SY.BasicData.Api.Read.Applications.Slaughter.CommandHandler
{
    public class GetSlaughterCommandHandler : IRequestHandler<GetSlaughterCommand, ApiResult<SlaughterModel>>
    {
        private readonly IBaseRepository<SlaughterModel> slaughterRepository;

        public GetSlaughterCommandHandler(IBaseRepository<SlaughterModel> slaughterRepository)
        {
            this.slaughterRepository = slaughterRepository;
        }

        public Task<ApiResult<SlaughterModel>> Handle(GetSlaughterCommand request, CancellationToken cancellationToken)
        {
            ApiResult<SlaughterModel> result = new ApiResult<SlaughterModel>();
            result.Code = ApiEnum.Success;
            result.Message = "屠宰信息展示成功";
            var list = slaughterRepository.GetAll().Where(x => x.Batch == request.Batch).FirstOrDefault();
            result.Data = list;
            return Task.FromResult(result);
        }
    }
}
